***********************************************************************************************
***
***	INTERTEMPORAL EVIDENCE ON THE STRATEGY OF POPULISM IN THE US (Gennaro, Lecce, Morelli)
***	Replication Package
***  
*** Appendix - Table A20
***
***********************************************************************************************



clear
est clear 

* Indicate location of the replication package here
cd "/Replication Package"

**********************************************
* Upload Data                            *****
**********************************************

use "3_data/for_analysis/congress_election_both.dta", clear

**********************************************
* Variables and sample                   *****
**********************************************

* Main outcome
local outvar "pop_dim2_s"

* Sample and controls
keep if uncont==0 & indep==0
local controls "female i.age_cat_num i.ethnicity2 i.educ_cat len_words i.election_year"


* Define populism of the opponent 
sort election district name
gen opponent_populism = .

by election_year district (name), sort: replace opponent_pop = pop_dim2_s[2] if _n == 1
by election_year district (name), sort: replace opponent_pop = pop_dim2_s[1] if _n == 2

* Mixed races
egen race_count = count(name), by(election district)
bys election_year district: egen temp = sum(outsider_correct)
gen mixed2race = ((race_count==2) & (temp==1)) if (race_count!=. & temp!=.)
drop temp 


************************************************************************
* Controlling for populism of the opponent in the main regression    ***
************************************************************************

est clear 

keep if race_count==2 

eststo: areg `outvar' i.outsider_correct opponent_pop `controls' , a(state) cluster(district)

eststo: areg `outvar' i.outsider_correct##c.econ opponent_pop `controls', a(state) cluster(district)

eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ `controls' opponent_pop , a(state) cluster(district)

* Fully interacted 
eststo: areg `outvar' i.outsider_correct##i.competitivedistricts##c.econ##c.opponent_pop `controls' , a(state) cluster(district)

* Save
esttab _all using "4_results/tables/tabA20.tex", f label replace booktabs alignment(D{.}{.}{-1}) keep(1.outsider_correct 1.competitivedistricts econ 1.outsider_correct#1.competitivedistricts 1.outsider_correct#c.econ 1.competitivedistricts#c.econ  1.outsider_correct#1.competitivedistricts#c.econ) s(N r2, fmt(0 2) label("Observations" "R-squared")) nomtitles star(* 0.10 ** 0.05 *** 0.01) r2 b(3) se(3) brac nonotes 
